package com.aita.diamond

import com.gd.magic.RootEntity
import com.gd.magic.Column

import com.gd.domain.party.Organization
import com.gd.domain.party.Operator

/**
 * 卡片库存单据基类
 *
 * @copyright(c) Copyright G&D Corporation 2007.
 * @author niedongbin
 * @see CardBill, BlankCardBill
 * @since v0.1
 */
abstract class AbstractBill extends RootEntity {

	@Column(notNull=true)
	Organization location 		//单据所属区域
	@Column(notNull=true)
	Date createTime				//单据创建时间
	@Column(notNull=true)
	Operator creator			//单据创建人
	
	@Column(index=true)
	Date recordTime 			//单据确认时间
	@Column(index=true)
	Date recordHour				//用于统计的确认的时间
	Operator operator 			//单据确认时的操作员
	
	@Column(dict="cardbill_type")
	int billType 				//单据类型,白卡单据类型和成品卡单据类型
	
	int amount 					//卡片数量
	boolean affectStock = true	//是否对库存有影响
	
	Long relatedId 				//对应撤销单据
	
	@Column(size=128)
	String description 			//描述
	
	public void preUpdate(boolean isNew) {
		if (isNew) {
			if (!location)
				location = loginService.currentOrg()
			if(!creator)
				creator = loginService.currentOperator()
			if(!createTime)
				createTime = new Date();
		}
		
		if(recordTime) {
			recordHour = formatService.getHourOfTime(recordTime)
		}
		
		super.preUpdate(isNew)
	}

}
